<template>
  <div class="ztjx">
    <div class="ztjx-text">
      <span class="left-text">专题精选</span>
      <span class="right-text" @click="gotomoreztjx">更多专题精选 ></span>
    </div>

    <div class="topic-grid">
      <div class="topic-item" v-for="topic in topicList" :key="topic.id" @click="gototopicdetail(topic.id)">
        <img :src="topic.picUrl" class="topic-image" :alt="topic.title">
        <div class="topic-content">
          <div class="topic-title">{{ topic.title }}</div>
          <div class="topic-subtitle">{{ topic.subtitle }}</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { getHomeData } from '@/api/home'
import { useRouter } from 'vue-router'
const router = useRouter()
const topicList = ref([])

onMounted(async () => {
  const response = await getHomeData()
  if (response.errno === 0 && response.data.topicList) {
    topicList.value = response.data.topicList
  }
})
const gototopicdetail = (id) => {
  router.push({
    path: '/goods/topic',
    query: { id }
  })
}
const gotomoreztjx=()=>{
    router.push({
    path: '/goods/moreztjx',
  })
}
</script>

<style scoped>
.ztjx {
  background: white;
  padding: 0 12px 12px;
}

.ztjx-text {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 0;
}

.left-text {
  font-size: 16px;
  font-weight: bold;
  color: #333;
}

.right-text {
  font-size: 12px;
  color: #999;
}

.topic-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.topic-item {
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.topic-image {
  width: 100%;
  height: 300px;
  object-fit: cover;
  display: block;
}

.topic-content {
  padding: 10px;
}

.topic-title {
  font-size: 14px;
  font-weight: 500;
  color: rgb(171, 149, 109);
  margin-bottom: 5px;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-align: center
}

.topic-subtitle {
  font-size: 12px;
  color: rgb(171, 149, 109);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 8px;
}
</style>